package com.kunbo.cn.service.impl.core.purchase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.kunbo.cn.dao.core.purchase.ProcurementPriceAdjustmentDao;
import com.kunbo.cn.entity.core.purchase.ProcurementPriceAdjustment;
import com.kunbo.cn.service.core.purchase.ProcurementPriceAdjustmentService;

@Service
public class ProcurementPriceAdjustmentImpl implements ProcurementPriceAdjustmentService {

	@Autowired
	private ProcurementPriceAdjustmentDao dao;
	@Autowired
	private JdbcTemplate jdbc;

	@Override
	public Boolean save(String order_code, String receiving_unit, String supplier, String settlement_method,
			float orginal_price, String create_user_id, String uuid, String taskid,String zxTime,String zdPople,String zdTime) {
		// TODO Auto-generated method stub
		ProcurementPriceAdjustment adjustment = new ProcurementPriceAdjustment();
		adjustment.setCreate_user_id(create_user_id);
		adjustment.setOrder_code(order_code);
		adjustment.setReceiving_unit(receiving_unit);
		adjustment.setSupplier(supplier);
		adjustment.setSettlement_method(settlement_method);
		adjustment.setOrginal_price(orginal_price);
		adjustment.setNew_price(0.0f);
		adjustment.setUuid(uuid);
		adjustment.setTaskid(taskid);
		adjustment.setZx_time(zxTime);
		adjustment.setZd_pople(zdPople);
		adjustment.setZd_time(zdTime);
		adjustment = dao.save(adjustment);
		if (adjustment != null)
			return true;
		else
			return false;
	}

	@Override
	public Boolean update(Integer id, String order_code, String receiving_unit, String supplier,
			String material_classification, String material, String settlement_method, Float orginal_price,
			Float new_price, String remarks) {
		// TODO Auto-generated method stub
		ProcurementPriceAdjustment adjustment = dao.findOne(id);
		adjustment.setOrder_code(order_code);
		adjustment.setReceiving_unit(receiving_unit);
		adjustment.setSupplier(supplier);
		adjustment.setMaterial_classification(material_classification);
		adjustment.setMaterial(material);
		adjustment.setSettlement_method(settlement_method);
		adjustment.setOrginal_price(orginal_price);
		adjustment.setNew_price(new_price);
		adjustment.setRemarks(remarks);
		adjustment = dao.save(adjustment);
		if (adjustment != null)
			return true;
		else
			return false;
	}

	@Override
	public ProcurementPriceAdjustment sel(Integer id) {
		// TODO Auto-generated method stub
		ProcurementPriceAdjustment adjustment = dao.findOne(id);
		return adjustment;
	}

	@Override
	public List<Map<String, Object>> selByCondition(String order_code, String material, String supplier, Integer page,
			Integer pageSize) {
		// TODO Auto-generated method stub
		String sql = "select * from business_cloud_purchase_modify_price where 1 = 1";
		if (order_code != null && !order_code.equals("")) {
			sql += " and  order_code like  '%" + order_code + "%'";
		}
		if (material != null && !material.equals("")) {
			sql += " and material like '%" + material + "%'";
		}
		if (supplier != null  && !supplier.equals("")) {
			sql += " and supplier like '%" + supplier + "%'";
		}
		String sqlCount = sql;
		System.out.println(sql);
		List<Map<String, Object>> list = jdbc.queryForList(sql);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("count", jdbc.queryForList(sqlCount).size());
		list.add(map);
		return list;
	}

}
